package com.sunnada.btfvilg.controller;

import com.sunnada.btfvilg.common.response.Result;
import com.sunnada.btfvilg.common.response.ResultFactory;
import com.sunnada.btfvilg.entity.Site;
import com.sunnada.btfvilg.model.request.SiteParamVo;
import com.sunnada.btfvilg.model.response.SiteListVo;
import com.sunnada.btfvilg.model.response.UserVo;
import com.sunnada.btfvilg.service.SiteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zsl
 * @title SiteController
 * @description: TODO
 */
@RestController
@RequestMapping("site")
@Api(tags = "快递网点管理")
public class SiteController {
    @Autowired
    SiteService siteService;

    @PostMapping("/addSite")
    @ApiOperation(value = "插入指定网点", httpMethod = "POST")
    public Result<UserVo> addSite(@Validated @RequestBody SiteParamVo siteVo){
        UserVo userVo=siteService.addSite(siteVo);
        return ResultFactory.success("添加成功",userVo);
    }

    @GetMapping("/deleteSiteById")
    @ApiOperation(value = "删除指定网点", httpMethod = "GET")
    public Result<Object> deleteSiteById( String id){
        siteService.delSite(id);
        return ResultFactory.success("删除成功", null);
    }

    @PostMapping("/updateSite")
    @ApiOperation(value = "修改指定网点信息", httpMethod = "POST")
    public Result<Object> updateSite(@Validated @RequestBody SiteParamVo siteVo){
        siteService.updateSite(siteVo);
        return ResultFactory.success("修改成功",null);
    }

    @GetMapping("/getAllSite")
    @ApiOperation(value = "获取所有网点信息", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "numPerPage", value = "每页记录数", dataType = "String", paramType = "query", required = true)
    })
    public Result<SiteListVo> getSiteList(Integer page, Integer numPerPage){
        SiteListVo siteList=siteService.getSiteList(page,numPerPage);
        return ResultFactory.success(siteList);
    }

    @PostMapping("/getSiteById")
    @ApiOperation(value = "获取指定网点信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sid", value = "网点id", dataType = "String", paramType = "query", required = true)
    })
    public Result<Site> getSiteById(String sid){
        Site site=siteService.getSiteById(sid);
        return ResultFactory.success(site);
    }

}
